/**
*      author: Y_Yao
*      created: 2025-03-29 17:41:53
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
queue<int> q;
int n,m;
vector<int> G[N];
int cnt[N],dest[N];
bool vis[N];

void bfs()
{
    memset(dest,INF,sizeof dest);
    dest[1] = 0,cnt[1] = 1;
    q.push(1);
    while(!q.empty())
    {
        int t = q.front();
        q.pop();
        vis[t] = true;
        for(auto& next : G[t])
        {
            if(dest[next] >= dest[t] + 1)
            {
                // if(!vis[next]) q.push(next);
                if(dest[next] > 1e8) q.push(next);
                dest[next] = dest[t] + 1;
                cnt[next] = (cnt[next] + cnt[t]) % mod;
            }
        }
    }   
}

void solve()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i++)
    {
        int u,v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    bfs();
    cout << cnt[n] << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}